{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "MYSQL_HOST=\"localhost:3306\"\n",
    "db = DATABASES={\n",
    "    # 本地配置\n",
    "    'user': 'root',\n",
    "    'password': '123456',\n",
    "    'host': MYSQL_HOST[:MYSQL_HOST.index(\":\")],\n",
    "    'database': \"test\",\n",
    "    'port': int(MYSQL_HOST[MYSQL_HOST.index(\":\") + 1:]),\n",
    "}\n",
    "        \n",
    "import pymysql\n",
    "db_con=pymysql.connect(**db)\n",
    "db_cur=db_con.cursor()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "*/\n",
      "\n",
      "\n",
      "\n",
      "SET FOREIGN_KEY_CHECKS=0;\n",
      "\n",
      "\n",
      "\n",
      "-- ----------------------------\n",
      "\n",
      "-- Table structure for access_log\n",
      "\n",
      "-- ----------------------------\n",
      "\n",
      "DROP TABLE IF EXISTS `access_log`;\n",
      "\n",
      "CREATE TABLE `access_log` (\n",
      "\n",
      "\n",
      "\n",
      "-- ----------------------------\n",
      "\n",
      "-- Table structure for cache_image_id_score\n",
      "\n",
      "-- ----------------------------\n",
      "\n",
      "DROP TABLE IF EXISTS `cache_image_id_score`;\n",
      "\n",
      "CREATE TABLE `cache_image_id_score` (\n",
      "\n",
      "\n",
      "\n",
      "-- ----------------------------\n",
      "\n",
      "-- Table structure for django_migrations\n",
      "\n",
      "-- ----------------------------\n",
      "\n",
      "DROP TABLE IF EXISTS `django_migrations`;\n",
      "\n",
      "CREATE TABLE `django_migrations` (\n",
      "\n",
      "\n",
      "\n",
      "-- ----------------------------\n",
      "\n",
      "-- Table structure for exception_log\n",
      "\n",
      "-- ----------------------------\n",
      "\n",
      "DROP TABLE IF EXISTS `exception_log`;\n",
      "\n",
      "CREATE TABLE `exception_log` (\n",
      "\n",
      "\n",
      "\n",
      "-- ----------------------------\n",
      "\n",
      "-- Table structure for id_info\n",
      "\n",
      "-- ----------------------------\n",
      "\n",
      "DROP TABLE IF EXISTS `id_info`;\n",
      "\n",
      "CREATE TABLE `id_info` (\n",
      "\n",
      "\n",
      "\n",
      "-- ----------------------------\n",
      "\n",
      "-- Table structure for image_id_score\n",
      "\n",
      "-- ----------------------------\n",
      "\n",
      "DROP TABLE IF EXISTS `image_id_score`;\n",
      "\n",
      "CREATE TABLE `image_id_score` (\n",
      "\n",
      "\n",
      "\n",
      "-- ----------------------------\n",
      "\n",
      "-- Table structure for yt_id_uri\n",
      "\n",
      "-- ----------------------------\n",
      "\n",
      "DROP TABLE IF EXISTS `yt_id_uri`;\n",
      "\n",
      "CREATE TABLE `yt_id_uri` (\n",
      "\n",
      "\n"
     ]
    },
    {
     "ename": "IndexError",
     "evalue": "string index out of range",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-41-986638d02bb5>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      9\u001b[0m                 \u001b[0mc\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreadline\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     10\u001b[0m         \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mc\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 11\u001b[1;33m         \u001b[1;32mif\u001b[0m \u001b[0mc\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0misalpha\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     12\u001b[0m             \u001b[1;32mwhile\u001b[0m \u001b[1;34m\";\"\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mc\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     13\u001b[0m                 \u001b[0msql\u001b[0m\u001b[1;33m+=\u001b[0m\u001b[0mc\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mIndexError\u001b[0m: string index out of range"
     ]
    }
   ],
   "source": [
    "skip=\"\"\n",
    "sql=\"\"\n",
    "with open(\"test_sql.sql\",\"r\",encoding=\"utf-8\") as f:\n",
    "    \n",
    "    sql_list = f.read().split(';')[:-1]  # sql文件最后一行加上;\n",
    "    sql_list = [x.replace('\\n', ' ') if '\\n' in x else x for x in sql_list]  # 将每段sql里的换行符改成空格\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
